using MoLingOverhaul.Common.Cores.Data;
using MoLingOverhaul.Common.Cores.Enum;
using System.IO;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace MoLingOverhaul
{
    public class MoLingOverhaul : Mod
    {
        public static MoLingOverhaul Instance;
        public SeasonData CurrentSeason;
        public override void Load()
        {
            Instance = this;
        }
        public override void Unload()
        {
            Instance = null;
        }
        public override void HandlePacket(BinaryReader reader, int whoAmI)
        {
            SeasonMessageType msgType = (SeasonMessageType)reader.ReadByte();
            switch (msgType)
            {
                case SeasonMessageType.RequestSeasonData:
                    if (Main.netMode == NetmodeID.Server)
                    {
                        ModPacket packet = Instance.GetPacket();
                        packet.Write((byte)SeasonMessageType.SyncSeasonData);
                        packet.Write(CurrentSeason.TotalDays);
                        packet.Write((int)CurrentSeason.CurrentSeason);
                        packet.Write(CurrentSeason.DaysInCurrentSeason);
                        packet.Send(whoAmI);
                    }
                    break;
                case SeasonMessageType.SyncSeasonData:
                    if (Main.netMode == NetmodeID.MultiplayerClient)
                    {
                        CurrentSeason.TotalDays = reader.ReadInt32();
                        CurrentSeason.CurrentSeason = (Season)reader.ReadInt32();
                        CurrentSeason.DaysInCurrentSeason = reader.ReadInt32();
                    }
                    break;
            }
        }    
    }
}
